import axios from "axios"
import qs from "qs"
export const requests = axios.create({
    baseURL:"",
    timeout: 1000,
    headers: {
        'Content-Type': ' application/x-www-form-urlencoded;charset=UTF-8',
        "Accept":"*/*",
        
    },
    transformRequest:function(data){
         data = qs.stringify(data)
           return data
    }
})
requests.interceptors.request.use(req => {
   
    console.log("进入请求拦截器，请求的配置如下");
    console.log(req);
    return req;
}, err => {
    console.log("进入请求拦截器失败")
    console.log(err);
   /*  return Promise.resolve(err) */
})
requests.interceptors.response.use(res => {
 
    console.log("进入反应拦截器");
    switch(res.status){
        case 200:
            console.log("状态码200:请求成功")
            break;
        case 404:
            console.log("状态码为404:找不到资源")
            break;
        case 500:
            console.log("状态码为500:找不到服务器")
            break;
    }
    console.log("进入响应拦截器");
    console.log(res)
    return res;
}, err => {
    
    console.log("进入响应拦截器失败")
    /* return Promise.resolve(err) */
})

